package com.ljkj.cordial.chat.presenter.response;

import android.app.Activity;

import com.lanjiu.lib.imclient.bus.EventConstants;
import com.lanjiu.lib.imclient.bus.MessageEvent;
import com.lanjiu.lib.utils.json.JsonUtils;

import org.greenrobot.eventbus.EventBus;

public abstract class AResponseBusinessPresenter implements IResponseBusinessPresenter {
    private IViewRefreshListener refreshListener;

    public AResponseBusinessPresenter setRefreshListener(IViewRefreshListener refreshListener) {
        this.refreshListener = refreshListener;
        return this;
    }

    @Override
    public void refresh(Activity activity) {
        if (refreshListener != null) {
            refreshListener.onViewRefresh(activity);
        }
    }

    @Override
    public void insert(Object... table) {

    }

    @Override
    public void delete(String... id) {

    }

    @Override
    public void update(Object... table) {

    }

    @Override
    public void postEvent(Object event) {
        try {
            MessageEvent ev = MessageEvent.cerateUiRefresh(EventConstants.Action.CHAT_MSG_RECEIVE);
            ev.setData(JsonUtils.toJson(event));
            EventBus.getDefault().post(ev);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private long msgTime;

    public void setMsgTime(long msgTime) {
        this.msgTime = msgTime;
    }

    public long getMsgTime() {
        return msgTime == 0L ? System.currentTimeMillis() : msgTime;
    }
}
